package com.my.demoredis.domain;

import org.springframework.data.annotation.Id;
import org.springframework.data.redis.core.RedisHash;
import org.springframework.data.redis.core.index.Indexed;

import java.util.List;

/**
 * Classname: Person
 * Package: com.my.demoredis.domain
 * Description:
 * 个人实体类
 * @Author Alex Liang
 * @Create 2024/7/6 下午8:32
 * @Version 1.0
 */

/**
 * 说明：注解@RedisHash(“persons”)，
 * 表明在redis数据库中开启一个persons的内存空间，
 * 所有person操作相关的数据均保存在此空间（redis是内存数据库）。
 */
@RedisHash("persons")
public class Person {

    /**
     * 主键
     */
    @Id
    private String id;
    /**
     * 生成二级索引，方便查询
     *
     * 名
     */
    @Indexed
    private String firstName;
    /**
     * 姓
     */
    @Indexed
    private String lastName;
    /**
     * 家庭地址
     */
    private Address address;

    /**
     * 家庭成员
     */
    private List<Family> familyList;

    public Person() {
    }

    public Person(String id, String firstName, String lastName, Address address, List<Family> familyList) {
        this.id = id;
        this.firstName = firstName;
        this.lastName = lastName;
        this.address = address;
        this.familyList = familyList;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getFirstName() {
        return firstName;
    }

    public void setFirstName(String firstName) {
        this.firstName = firstName;
    }

    public String getLastName() {
        return lastName;
    }

    public void setLastName(String lastName) {
        this.lastName = lastName;
    }

    public Address getAddress() {
        return address;
    }

    public void setAddress(Address address) {
        this.address = address;
    }

    public List<Family> getFamilyList() {
        return familyList;
    }

    public void setFamilyList(List<Family> familyList) {
        this.familyList = familyList;
    }

    @Override
    public String toString() {
        return "Person{" +
                "id='" + id + '\'' +
                ", firstName='" + firstName + '\'' +
                ", lastName='" + lastName + '\'' +
                ", address=" + address +
                ", familyList=" + familyList +
                '}';
    }
}
